"use strict";
cc._RF.push(module, '6b209X9V79HAbgaI2cogShP', 'TouchBlocker2');
// eazax-ccc/components/TouchBlocker2.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
/**
 * 点击屏蔽器组件
 * @see TouchBlocker2.ts https://gitee.com/ifaswind/eazax-ccc/blob/master/components/TouchBlocker2.ts
 */
var TouchBlocker2 = /** @class */ (function (_super) {
    __extends(TouchBlocker2, _super);
    function TouchBlocker2() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        /** 可被点击的节点列表 */
        _this.allowList = [];
        /** 是否屏蔽点击 */
        _this.blocked = false;
        /** 是否设为常驻节点模式 */
        _this.persist = false;
        return _this;
    }
    TouchBlocker2_1 = TouchBlocker2;
    TouchBlocker2.prototype.onLoad = function () {
        this.init();
        this.registerEvent();
    };
    TouchBlocker2.prototype.onDestroy = function () {
        this.unregisterEvent();
        TouchBlocker2_1.instance = null;
    };
    /**
     * 初始化
     */
    TouchBlocker2.prototype.init = function () {
        if (this.persist) {
            // 设为最外层节点
            this.node.setParent(cc.Canvas.instance.node);
            this.node.setSiblingIndex(cc.macro.MAX_ZINDEX);
            // 设为常驻节点
            cc.game.addPersistRootNode(this.node);
        }
        TouchBlocker2_1.instance = this;
    };
    /**
     * 订阅事件
     */
    TouchBlocker2.prototype.registerEvent = function () {
        this.node.on(cc.Node.EventType.TOUCH_START, this.onEvent, this);
        this.node.on(cc.Node.EventType.TOUCH_MOVE, this.onEvent, this);
        this.node.on(cc.Node.EventType.TOUCH_END, this.onEvent, this);
        // 取消吞噬事件
        this.setSwallowTouches(false);
    };
    /**
     * 移除订阅事件
     */
    TouchBlocker2.prototype.unregisterEvent = function () {
        this.node.targetOff(this);
    };
    /**
     * 事件回调
     * @param event 事件
     */
    TouchBlocker2.prototype.onEvent = function (event) {
        if (this.blocked && !this.clickOnAnyTarget(event.getLocation())) {
            event.stopPropagationImmediate();
        }
    };
    /**
     * 是否点击到任意目标上
     * @param pos 点击位置（世界坐标系）
     */
    TouchBlocker2.prototype.clickOnAnyTarget = function (pos) {
        for (var i = 0; i < this.allowList.length; i++) {
            var rect = this.allowList[i].getBoundingBoxToWorld();
            if (rect.contains(pos)) {
                return true;
            }
        }
        return false;
    };
    /**
     * 设置节点是否吞噬点击事件
     * @param swallow 状态
     */
    TouchBlocker2.prototype.setSwallowTouches = function (swallow) {
        this.node._touchListener.setSwallowTouches(swallow);
    };
    /**
     * 增加可点击的节点
     * @param nodes 节点
     */
    TouchBlocker2.addTargets = function (nodes) {
        var _a;
        if (Array.isArray(nodes)) {
            (_a = this.instance.allowList).push.apply(_a, nodes);
        }
        else {
            this.instance.allowList.push(nodes);
        }
    };
    /**
     * 设置唯一可点击的目标（此行为会清空原有的可点击节点列表）
     * @param node 节点
     */
    TouchBlocker2.setTarget = function (node) {
        this.clearTargets();
        this.instance.allowList.push(node);
    };
    /**
     * 清空可点击节点列表
     */
    TouchBlocker2.clearTargets = function () {
        this.instance.allowList.length = 0;
    };
    /** 启用屏蔽 */
    TouchBlocker2.on = function () {
        this.instance.blocked = true;
    };
    /** 禁用屏蔽 */
    TouchBlocker2.off = function () {
        this.instance.blocked = false;
    };
    var TouchBlocker2_1;
    /** 实例 */
    TouchBlocker2.instance = null;
    __decorate([
        property({ type: [cc.Node], tooltip: CC_DEV && '可点击的节点列表' })
    ], TouchBlocker2.prototype, "allowList", void 0);
    __decorate([
        property({ tooltip: CC_DEV && '是否屏蔽点击' })
    ], TouchBlocker2.prototype, "blocked", void 0);
    __decorate([
        property({ tooltip: CC_DEV && '是否设为常驻节点模式' })
    ], TouchBlocker2.prototype, "persist", void 0);
    TouchBlocker2 = TouchBlocker2_1 = __decorate([
        ccclass
    ], TouchBlocker2);
    return TouchBlocker2;
}(cc.Component));
exports.default = TouchBlocker2;

cc._RF.pop();